Repository navigation
Wake the event loop on SIGINT so async cells interrupt promptly - #1614
Open
vivekghodekar001 wants to merge 2 commits into
Open
vivekghodekar001 wants to merge 2 commits into
vivekghodekar001 wants to merge 2 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #881
While an async cell runs,
_cancel_on_sigintinstalls a Python-level SIGINT handler. CPython only runs Python signal handlers when the main thread executes bytecode, so when the loop is parked in its selector (for example awaitingasyncio.sleep), the handler does not run until something else wakes the loop. Interrupting the cell therefore only takes effect when the sleep ends.This registers a wakeup fd for the duration of
_cancel_on_sigint, the same mechanismloop.add_signal_handler()uses, so SIGINT wakes the selector and the cancellation lands promptly. An existing wakeup fd is left untouched, and the fd and previous handler are restored when the context exits.Adds a regression test that sends SIGINT from a timer thread while a future sleeps and asserts cancellation lands promptly.